
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ContentOverContainer.Common;
using ContentOverContainer.Common.Converter;
using Roslyn.Compilers;
using Roslyn.Compilers.CSharp;
using Roslyn.Compilers.Common;
using Roslyn.Services;
using Roslyn.Services.Formatting;

namespace ContentOverContainer
{



    /// <summary>
    /// Builds a list of propety declaration nodes annotated with the MultiplicityAttribute together with their replacements
    /// and a list of their references.
    /// It akes care that field refenrences  used in the property getter and setter are already replaced.
    /// </summary>
    /// <author>Harald Binkle</author>
    public class PropertyWalker : BaseWalker
    {
        public PropertyWalker(ISolution pSolution, ReferencesList pReferences, ChangeNodeInfoList pChangeNodePairs) : base(pSolution, pReferences, pChangeNodePairs)
        {
        }

        public override void VisitPropertyDeclaration(PropertyDeclarationSyntax node)
        {
            PropertyDeclarationSyntax syntaxNode = node;
            if (syntaxNode == null) return;

            var multiplicityAtt = node.AttributeLists.GetMultiplicityAttributes();
            if (multiplicityAtt == null)
                return;

            var multiInfo = multiplicityAtt.GetMultiplicityInfo(node.Type);
            
            var references = node.FindAllReferences(m_SemModel, this.m_Solution).Cast<SyntaxNode>();
            m_References.Add(references, multiInfo, m_Document);

            var newnode = node;
            if (multiInfo.Type != null)
                newnode = newnode.ChangeToMultiplicityType(multiInfo.Type);

            var changeNode = newnode.RemoveMultiplicityAttribute(newnode.AttributeLists, true);

            m_Replacements.Add(node, changeNode, m_Document);
        }


    }
}
